package dp.bag_problem.one_zero;

import java.util.Scanner;

public class BestZeroOneBag {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int V = sc.nextInt();
        int[] v = new int[N + 1];
        int[] w = new int[N + 1];
        for (int i = 1; i <= N; i++) {
            v[i] = sc.nextInt();
            w[i] = sc.nextInt();
        }
        // 空间压缩题解参考 https://www.acwing.com/activity/content/code/content/625657/
        int[] dp = new int[V + 1];
        for (int i = 1; i <= N; i++) {
            for (int j = V; j >= 1; j--) {
                if (j >= v[i]) {
                    // 如果选择第 i 件物品，那么背包剩余容量就是 j - v[i]
                    dp[j] = Math.max(dp[j], dp[j - v[i]] + w[i]);
                }
            }
        }
        System.out.println(dp[V]);
    }
}
